package demo2;

public enum TestEnum {
    //枚举对象
    RED(1, "红色"),
    BLACK(2, "黑色"),
    GREEN(3, "绿色");

    public String color;
    public int ordinal;

    //当枚举对象有参数后，需要提供相应的构造函数
    //枚举的构造函数默认是私有的
    private TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }


    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + " 索引:" + testEnums[i].ordinal());
        }

        System.out.println("============");
        TestEnum testEnum = TestEnum.valueOf("GREEN");
        System.out.println(testEnum);

        System.out.println(RED.compareTo(GREEN));
    }


    public static void main1(String[] args) {
        TestEnum color = RED;
        switch (color) {
            case GREEN:
                System.out.println("GREEN");
                break;
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            default:
                System.out.println("color error");
                break;
        }
    }
}
